package com.yoda.youdianda.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yoda.youdianda.domain.YddLink;
import com.yoda.youdianda.mapper.YddLinkMapper;
import com.yoda.youdianda.service.YddLinkService;
import com.yoda.youdianda.vo.PageResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class YddLinkServiceImpl implements YddLinkService {
    @Autowired
    private YddLinkMapper yddLinkMapper;

    @Override
    public YddLink rowInfo(Integer id) {
        YddLink yddLink = yddLinkMapper.selectById(id);
        return yddLink;
    }

    @Override
    public void updateYddLink(YddLink yddLink) {
        yddLinkMapper.updateById(yddLink);
    }

    @Override
    public void deleteById(Integer id) {
        yddLinkMapper.deleteById(id);
    }

    @Override
    public void addYddLink(YddLink yddLink) {
        yddLinkMapper.insert(yddLink);
    }

    @Override
    public PageResult selectYddLinkList(String type, Integer page, Integer limit) {
        Page yddLinkPage = new Page(page, limit);
        LambdaQueryWrapper<YddLink> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotEmpty(type), YddLink::getType, type);
        yddLinkPage = yddLinkMapper.selectPage(yddLinkPage, lqw);
        return new PageResult((int) yddLinkPage.getCurrent(), (int) yddLinkPage.getSize(), (int) yddLinkPage.getTotal(), yddLinkPage.getRecords());
    }
}
